package org.admin.entity.dto;

import core.validate.Rule;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.admin.entity.BaseDto;

import java.util.List;
import java.util.Objects;

@Data
@EqualsAndHashCode(callSuper = true)
public class PermsGroupDto extends BaseDto<PermsGroupDto> {
    protected PermsGroupDto inst(){ return this; }
    public PermsGroupDto(){
        addRule(new Rule<?>[]{
                Rule.Number("id")
                        .onPreCheck(value -> {
                            if(value instanceof String && value.equals("")){
                                return null;
                            }
                            return value;
                        }).min(1, "指定ID错误"),
                Rule.String("name").max(16, "权限组名称长度过长"),
                Rule.String("detail").max(200, "描述内容过长请缩减文字"),
                Rule.Number("current").min(1, "当前分页错误"),
                Rule.Number("size").onPreCheck(value -> {
                    return Objects.requireNonNullElse(value, 20);
                }).min(1, "分页数量错误"),
                Rule.Array("ids").min(1, "未指定删除项"),
        });
    }

    private Integer id;
    private String name;
    private String detail;
    private List<Integer> ids;
    private Integer current;
    private Integer size;
}
